use clap::{Args, Parser, Subcommand};

#[derive(Parser)]
#[command(about)]
struct Cli {
    #[command(subcommand)]
    command: Commands,
}

#[derive(Subcommand)]
enum Commands {
    Change(ChangeCommand),
    Validate(ValidateCommand),
}

#[derive(Args)]
struct ChangeCommand {
    #[arg(short, long, required(true))]
    password: String,
}

#[derive(Args)]
struct ValidateCommand {
    #[arg(short, long, required(true))]
    password: String,
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    fern::Dispatch::new()
        .format(|out, message, record| {
            out.finish(format_args!(
                "{}[{}][{}] {}",
                chrono::Local::now().format("[%Y-%m-%d][%H:%M:%S]"),
                record.target(),
                record.level(),
                message
            ))
        })
        .level(log::LevelFilter::Info)
        .chain(std::io::stdout())
        .apply().unwrap();
    log::info!("cli started");
    let cli = Cli::parse();
    match cli.command {
        Commands::Change(change) => {
            log::info!("change password to {}", change.password);
        }
        Commands::Validate(validate) => {
            log::info!("validate password {}", validate.password);
        }
    }
    Ok(())
}
